<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>赋值、浅拷贝和深拷贝的区别 | XiaoZhang’s Blog</title><meta name="keywords" content="前端,ES6,原型链"><meta name="author" content="XiaoZhang,邮箱"><meta name="copyright" content="XiaoZhang"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="description" content="一、赋值（Copy）赋值是将某一数值或对象赋给某个变量的过程，分为下面 2 部分  基本数据类型：赋值，赋值之后两个变量互不影响 引用数据类型：赋址，两个变量具有相同的引用，指向同一个对象，相互之间有影响对基本类型进行赋值操作，两个变量互不影响。  12345678let a &#x3D; &quot;XiaoZhang&quot;;let b &#x3D; a;console.log(b); &#x2F;&#x2F; XiaoZhan">
<meta property="og:type" content="article">
<meta property="og:title" content="赋值、浅拷贝和深拷贝的区别">
<meta property="og:url" content="https://zhang_shaolong.gitee.io/posts/bed3,.html">
<meta property="og:site_name" content="XiaoZhang’s Blog">
<meta property="og:description" content="一、赋值（Copy）赋值是将某一数值或对象赋给某个变量的过程，分为下面 2 部分  基本数据类型：赋值，赋值之后两个变量互不影响 引用数据类型：赋址，两个变量具有相同的引用，指向同一个对象，相互之间有影响对基本类型进行赋值操作，两个变量互不影响。  12345678let a &#x3D; &quot;XiaoZhang&quot;;let b &#x3D; a;console.log(b); &#x2F;&#x2F; XiaoZhan">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://zhang_shaolong.gitee.io/cover/copy.png">
<meta property="article:published_time" content="2021-06-30T07:35:00.000Z">
<meta property="article:modified_time" content="2021-11-30T09:22:49.299Z">
<meta property="article:author" content="XiaoZhang">
<meta property="article:tag" content="前端">
<meta property="article:tag" content="ES6">
<meta property="article:tag" content="原型链">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://zhang_shaolong.gitee.io/cover/copy.png"><link rel="shortcut icon" href="/img/dvoe.png"><link rel="canonical" href="https://zhang_shaolong.gitee.io/posts/bed3,"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?ffcbb436e2f4b0326f38f622b85c0f07";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"top-right"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '赋值、浅拷贝和深拷贝的区别',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-11-30 17:22:49'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><div class="aplayer" data-id="7031037814" data-server="netease" data-type="playlist" data-fixed="true" data-listFolded="false" data-order="random" data-preload="none"></div><link rel="stylesheet" href="https://cdn.bootcss.com/aplayer/1.10.1/APlayer.min.css"><script src="https://cdn.bootcss.com/aplayer/1.10.1/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/meting@1.2.0/dist/Meting.min.js"></script><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    document.addEventListener('pjax:complete', detectApple)})(window)</script><link rel="stylesheet" href="/css/bg.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/static-butterfly/dist/css/index.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css"  media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://zhang_shaolong.gitee.io/css/bg.css"><div id="aplayer"></div><!--script(src="https://cdn.jsdelivr.net/gh/radium-bit/res@master/live2d/autoload.js" async)--><!--script(src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js" async)--><!-- hexo injector head_end start --><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-footer-beautify@1.0.0/lib/runtime.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiperstyle.css" media="print" onload="this.media='all'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="XiaoZhang’s Blog" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpeg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">25</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">20</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/navigation/"><i class="fa-fw fas fa-map"></i><span> 导航</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 博客</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/photos/"><i class="fa-fw fas fa-camera"></i><span> 相册</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/bb/"><i class="fa-fw fas fa-bomb"></i><span> 动态</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友人帐</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-comments"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/my-profile/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/../cover/copy.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">XiaoZhang’s Blog</a><div id="he-plugin-simple"></div></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/navigation/"><i class="fa-fw fas fa-map"></i><span> 导航</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 博客</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/photos/"><i class="fa-fw fas fa-camera"></i><span> 相册</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/bb/"><i class="fa-fw fas fa-bomb"></i><span> 动态</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友人帐</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-comments"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/my-profile/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">赋值、浅拷贝和深拷贝的区别</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-06-30T07:35:00.000Z" title="发表于 2021-06-30 15:35:00">2021-06-30</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-11-30T09:22:49.299Z" title="更新于 2021-11-30 17:22:49">2021-11-30</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="赋值、浅拷贝和深拷贝的区别"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="一、赋值（Copy）"><a href="#一、赋值（Copy）" class="headerlink" title="一、赋值（Copy）"></a>一、赋值（Copy）</h2><p>赋值是将某一数值或对象赋给某个变量的过程，分为下面 2 部分</p>
<ul>
<li>基本数据类型：赋值，赋值之后两个变量互不影响</li>
<li>引用数据类型：赋址，两个变量具有相同的引用，指向同一个对象，相互之间有影响<br>对基本类型进行赋值操作，两个变量互不影响。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">let a = &quot;XiaoZhang&quot;;</span><br><span class="line">let b = a;</span><br><span class="line">console.log(b); // XiaoZhang</span><br><span class="line"></span><br><span class="line">a = &quot;change&quot;;</span><br><span class="line">console.log(a);// change</span><br><span class="line">console.log(b);// XiaoZhang</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>对引用类型进行赋址操作，两个变量指向同一个对象，改变变量 a 之后会影响变量 b，哪怕改变的只是对象 a 中的基本类型数据。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">let a = &#123;</span><br><span class="line">    name: &quot;XiaoZhang&quot;,</span><br><span class="line">    content: &#123;</span><br><span class="line">      age: 21,</span><br><span class="line">      sex: &quot;男&quot;</span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br><span class="line">let b = a;</span><br><span class="line">console.log(b);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;XiaoZhang&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 21,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br><span class="line"></span><br><span class="line">a.name = &quot;change&quot;;</span><br><span class="line">a.content.age = 27;</span><br><span class="line">console.log(a);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;change&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 27,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br><span class="line"></span><br><span class="line">console.log(b);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;change&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 27,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br></pre></td></tr></table></figure>
<p>通常在开发中并不希望改变变量 a 之后会影响到变量 b，这时就需要用到浅拷贝和深拷贝。</p>
<h2 id="二、浅拷贝（Shallow-Copy）"><a href="#二、浅拷贝（Shallow-Copy）" class="headerlink" title="二、浅拷贝（Shallow Copy）"></a>二、浅拷贝（Shallow Copy）</h2><h4 id="1-什么是浅拷贝"><a href="#1-什么是浅拷贝" class="headerlink" title="1.什么是浅拷贝?"></a>1.什么是浅拷贝?</h4><p>创建一个新对象，这个对象有着原始对象属性值的一份精确拷贝。如果属性是基本类型，拷贝的就是基本类型的值，如果属性是引用类型，拷贝的就是内存地址 ，所以如果其中一个对象改变了这个地址，就会影响到另一个对象。</p>
<p>简单来说可以理解为浅拷贝只解决了第一层的问题，拷贝第一层的 <strong>基本类型值</strong> ，以及第一层的 <strong>引用类型地址</strong>。</p>
<h4 id="2、浅拷贝使用场景"><a href="#2、浅拷贝使用场景" class="headerlink" title="2、浅拷贝使用场景"></a>2、浅拷贝使用场景</h4><h6 id="Object-assign"><a href="#Object-assign" class="headerlink" title="Object.assign()"></a>Object.assign()</h6><p>Object.assign() 方法用于将所有可枚举属性的值从一个或多个源对象复制到目标对象。它将返回目标对象。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">let a = &#123;</span><br><span class="line">    name: &quot;XiaoZhang&quot;,</span><br><span class="line">    content: &#123;</span><br><span class="line">      age: 21,</span><br><span class="line">      sex: &quot;男&quot;</span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br><span class="line">let b = Object.assign(&#123;&#125;, a);</span><br><span class="line">console.log(b);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;XiaoZhang&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 21,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br><span class="line"></span><br><span class="line">a.name = &quot;change&quot;;</span><br><span class="line">a.content.age = 27;</span><br><span class="line">console.log(a);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;change&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 27,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br><span class="line"></span><br><span class="line">console.log(b);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;XiaoZhang&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 27,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br></pre></td></tr></table></figure>
<p>上面代码改变对象 a 之后，对象 b 的基本属性保持不变。但是当改变对象 a 中的对象 content 时，对象 b 相应的位置也发生了变化。</p>
<h6 id="展开语法-·-·-·"><a href="#展开语法-·-·-·" class="headerlink" title="展开语法 · · ·"></a>展开语法 <mark>· · ·</mark></h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">let a = &#123;</span><br><span class="line">    name: &quot;XiaoZhang&quot;,</span><br><span class="line">    content: &#123;</span><br><span class="line">      age: 21,</span><br><span class="line">      sex: &quot;男&quot;</span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br><span class="line">let b = &#123;...a&#125;;</span><br><span class="line">console.log(b);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;XiaoZhang&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 21,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br><span class="line"></span><br><span class="line">a.name = &quot;change&quot;;</span><br><span class="line">a.content.age = 27;</span><br><span class="line">console.log(a);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;change&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 27,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br><span class="line"></span><br><span class="line">console.log(b);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;XiaoZhang&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 27,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br></pre></td></tr></table></figure>
<p>通过代码可以看出实际效果和 Object.assign() 是一样的。</p>
<h6 id="手写实现浅拷贝"><a href="#手写实现浅拷贝" class="headerlink" title="手写实现浅拷贝"></a>手写实现浅拷贝</h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">function shallowCopy(obj) &#123;</span><br><span class="line">  var target = &#123;&#125;;</span><br><span class="line">  for (let i in obj) &#123;</span><br><span class="line">    if (obj.hasOwnproperty(i)) &#123;</span><br><span class="line">      target[i] = obj[i];</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  return target;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="三、深拷贝（Deep-Copy）"><a href="#三、深拷贝（Deep-Copy）" class="headerlink" title="三、深拷贝（Deep Copy）"></a>三、深拷贝（Deep Copy）</h2><h4 id="1、什么是深拷贝？"><a href="#1、什么是深拷贝？" class="headerlink" title="1、什么是深拷贝？"></a>1、什么是深拷贝？</h4><p>深拷贝会拷贝所有的属性，并拷贝属性指向的动态分配的内存。当对象和它所引用的对象一起拷贝时即发生深拷贝。深拷贝相比于浅拷贝速度较慢并且花销较大。拷贝前后两个对象互不影响。</p>
<h4 id="2、深拷贝使用场景"><a href="#2、深拷贝使用场景" class="headerlink" title="2、深拷贝使用场景"></a>2、深拷贝使用场景</h4><h6 id="JSON-parse-JSON-stringify-object"><a href="#JSON-parse-JSON-stringify-object" class="headerlink" title="JSON.parse(JSON.stringify(object))"></a>JSON.parse(JSON.stringify(object))</h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">let a = &#123;</span><br><span class="line">    name: &quot;XiaoZhang&quot;,</span><br><span class="line">    content: &#123;</span><br><span class="line">      age: 21,</span><br><span class="line">      sex: &quot;男&quot;</span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br><span class="line">let b = JSON.parse(JSON.stringify(a));</span><br><span class="line">console.log(b);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;XiaoZhang&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 21,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br><span class="line"></span><br><span class="line">a.name = &quot;change&quot;;</span><br><span class="line">a.content.age = 27;</span><br><span class="line">console.log(a);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;change&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 27,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br><span class="line"></span><br><span class="line">console.log(b);</span><br><span class="line">//&#123;</span><br><span class="line">//     name: &quot;XiaoZhang&quot;,</span><br><span class="line">//     content: &#123;</span><br><span class="line">//       age: 21,</span><br><span class="line">//       sex: &quot;男&quot;</span><br><span class="line">//     &#125;  </span><br><span class="line">// &#125;</span><br></pre></td></tr></table></figure>
<p>完全改变变量 a 之后对 b 没有任何影响，这就是深拷贝的魔力。</p>
<p>我们看下对数组深拷贝效果如何。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">let a = [0, &quot;1&quot;, [2, 3]];</span><br><span class="line">let b = JSON.parse(JSON.stringify( a.slice(1) ));</span><br><span class="line">console.log(b);</span><br><span class="line">// [&quot;1&quot;, [2, 3]]</span><br><span class="line"></span><br><span class="line">a[1] = &quot;99&quot;;</span><br><span class="line">a[2][0] = 4;</span><br><span class="line">console.log(a);</span><br><span class="line">// [0, &quot;99&quot;, [4, 3]]</span><br><span class="line"></span><br><span class="line">console.log(b);</span><br><span class="line">//  [&quot;1&quot;, [2, 3]]</span><br></pre></td></tr></table></figure>
<p>对数组深拷贝之后，改变原数组不会影响到拷贝之后的数组。</p>
<p>但是该方法有以下几个问题。</p>
<p>1、会忽略 undefined</p>
<p>2、会忽略 symbol</p>
<p>3、不能序列化函数</p>
<p>4、不能解决循环引用的对象</p>
<p>5、不能正确处理new Date()</p>
<p>6、不能处理正则</p>
<ul>
<li>undefined、symbol 和函数这三种情况，会直接忽略。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">let obj = &#123;</span><br><span class="line">    name: &quot;XiaoZhang&quot;</span><br><span class="line">    a: undefined,</span><br><span class="line">    b: Symbol(&quot;XiaoZhang&quot;),</span><br><span class="line">    c: function() &#123;&#125;</span><br><span class="line">&#125;</span><br><span class="line">console.log(obj);</span><br><span class="line">// &#123;</span><br><span class="line">// 	name: &quot;XiaoZhang&quot;</span><br><span class="line">//  a: undefined,</span><br><span class="line">//  b: Symbol(&quot;XiaoZhang&quot;),</span><br><span class="line">//  c: function() &#123;&#125;</span><br><span class="line">// &#125;</span><br><span class="line"></span><br><span class="line">let b = JSON.parse(JSON.stringify(obj));</span><br><span class="line">console.log(b);</span><br><span class="line">// &#123;name: &quot;XiaoZhang&quot;&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>循环引用情况下，会报错。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">let obj = &#123;</span><br><span class="line">    a: 1,</span><br><span class="line">    b: &#123;</span><br><span class="line">        c: 2,</span><br><span class="line">   		d: 3</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">obj.a = obj.b;</span><br><span class="line">obj.b.c = obj.a;</span><br><span class="line"></span><br><span class="line">let b = JSON.parse(JSON.stringify(obj));</span><br><span class="line">// Uncaught TypeError: Converting circular structure to JSON</span><br></pre></td></tr></table></figure>

<ul>
<li>new Date 情况下，转换结果不正确。</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">new Date();</span><br><span class="line">// Mon Dec 24 2018 10:59:14 GMT+0800 (China Standard Time)</span><br><span class="line"></span><br><span class="line">JSON.stringify(new Date());</span><br><span class="line">// &quot;&quot;2018-12-24T02:59:25.776Z&quot;&quot;</span><br><span class="line"></span><br><span class="line">JSON.parse(JSON.stringify(new Date()));</span><br><span class="line">// &quot;2018-12-24T02:59:41.523Z&quot;</span><br></pre></td></tr></table></figure>
<p>解决方法转成字符串或者时间戳就好了。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">let date = (new Date()).valueOf();</span><br><span class="line">// 1545620645915</span><br><span class="line"></span><br><span class="line">JSON.stringify(date);</span><br><span class="line">// &quot;1545620673267&quot;</span><br><span class="line"></span><br><span class="line">JSON.parse(JSON.stringify(date));</span><br><span class="line">// 1545620658688</span><br></pre></td></tr></table></figure>
<ul>
<li>正则情况下<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">let obj = &#123;</span><br><span class="line">    name: &quot;XiaoZhang&quot;,</span><br><span class="line">    a: /&quot;123&quot;/</span><br><span class="line">&#125;</span><br><span class="line">console.log(obj);</span><br><span class="line">// &#123;name: &quot;XiaoZhang&quot;, a: /&quot;123&quot;/&#125;</span><br><span class="line"></span><br><span class="line">let b = JSON.parse(JSON.stringify(obj));</span><br><span class="line">console.log(b);</span><br><span class="line">// &#123;name: &quot;XiaoZhang&quot;, a:&#123;&#125;&#125;</span><br></pre></td></tr></table></figure>
<h4 id="递归"><a href="#递归" class="headerlink" title="递归"></a>递归</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">//使用递归的方式实现数组、对象的深拷贝</span><br><span class="line">function deepClone1(obj) &#123;</span><br><span class="line">  //判断拷贝的要进行深拷贝的是数组还是对象，是数组的话进行数组拷贝，对象的话进行对象拷贝</span><br><span class="line">  var objClone = Array.isArray(obj) ? [] : &#123;&#125;;</span><br><span class="line">  //进行深拷贝的不能为空，并且是对象或者是</span><br><span class="line">  if (obj &amp;&amp; typeof obj === &quot;object&quot;) &#123;</span><br><span class="line">    for (key in obj) &#123;</span><br><span class="line">      if (obj.hasOwnProperty(key)) &#123;</span><br><span class="line">        if (obj[key] &amp;&amp; typeof obj[key] === &quot;object&quot;) &#123;</span><br><span class="line">          objClone[key] = deepClone1(obj[key]);</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">          objClone[key] = obj[key];</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  return objClone;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="通过jQuery的extend方法实现深拷贝"><a href="#通过jQuery的extend方法实现深拷贝" class="headerlink" title="通过jQuery的extend方法实现深拷贝"></a>通过jQuery的extend方法实现深拷贝</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">var array = [1,2,3,4];</span><br><span class="line">var newArray = $.extend(true,[],array);</span><br></pre></td></tr></table></figure>
<h4 id="lodash函数库实现深拷贝"><a href="#lodash函数库实现深拷贝" class="headerlink" title="lodash函数库实现深拷贝"></a>lodash函数库实现深拷贝</h4><blockquote>
<p>lodash很热门的函数库，提供了 lodash.cloneDeep()实现深拷贝</p>
</blockquote>
</li>
</ul>
<h2 id="四、总结"><a href="#四、总结" class="headerlink" title="四、总结"></a>四、总结</h2><table>
<thead>
<tr>
<th align="center">–</th>
<th align="center">和原数据是否指向同一对象</th>
<th align="center">第一层数据为基本数据类型</th>
<th align="center">原数据中包含子对象</th>
</tr>
</thead>
<tbody><tr>
<td align="center">赋值</td>
<td align="center">是</td>
<td align="center">改变会使原数据一同改变</td>
<td align="center">改变会使原数据一同改变</td>
</tr>
<tr>
<td align="center">浅拷贝</td>
<td align="center">否</td>
<td align="center">改变不会使原数据一同改变</td>
<td align="center">改变会使原数据一同改变</td>
</tr>
<tr>
<td align="center">浅拷贝</td>
<td align="center">否</td>
<td align="center">改变不会使原数据一同改变</td>
<td align="center">改变不会使原数据一同改变</td>
</tr>
</tbody></table>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:邮箱">XiaoZhang</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://zhang_shaolong.gitee.io/posts/bed3,.html">https://zhang_shaolong.gitee.io/posts/bed3,.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://zhang_shaolong.gitee.io" target="_blank">XiaoZhang’s Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E5%89%8D%E7%AB%AF/">前端</a><a class="post-meta__tags" href="/tags/ES6/">ES6</a><a class="post-meta__tags" href="/tags/%E5%8E%9F%E5%9E%8B%E9%93%BE/">原型链</a></div><div class="post_share"><div class="social-share" data-image="/../cover/copy.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/213d.html"><img class="prev-cover" src="/../cover/business.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">双飞翼布局和圣杯布局</div></div></a></div><div class="next-post pull-right"><a href="/posts/81.html"><img class="next-cover" src="/../cover/business.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">CSS盒模型</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/3ebb.html" title="ES6 新语法"><img class="cover" src="https://api.ixiaowai.cn/gqapi/gqapi.php" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-19</div><div class="title">ES6 新语法</div></div></a></div><div><a href="/posts/81.html" title="CSS盒模型"><img class="cover" src="/../cover/business.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-23</div><div class="title">CSS盒模型</div></div></a></div><div><a href="/posts/f40f.html" title="JavaScript类型判断"><img class="cover" src="/../cover/JavaScript.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-11-17</div><div class="title">JavaScript类型判断</div></div></a></div><div><a href="/posts/488c.html" title="JS函数柯里化"><img class="cover" src="/../cover/currying.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-12-07</div><div class="title">JS函数柯里化</div></div></a></div><div><a href="/posts/dc34.html" title="Socket.IO使用"><img class="cover" src="/../cover/socket.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-11-30</div><div class="title">Socket.IO使用</div></div></a></div><div><a href="/posts/9d4c.html" title="html标签"><img class="cover" src="/../cover/business.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-04-02</div><div class="title">html标签</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpeg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">XiaoZhang</div><div class="author-info__description">彼方尚有荣光在！！！ </div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">25</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">20</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/zhang_shaolong"><i class="fab fa-github-alt"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">有朋自远方来，不亦乐乎！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E8%B5%8B%E5%80%BC%EF%BC%88Copy%EF%BC%89"><span class="toc-number">1.</span> <span class="toc-text">一、赋值（Copy）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E6%B5%85%E6%8B%B7%E8%B4%9D%EF%BC%88Shallow-Copy%EF%BC%89"><span class="toc-number">2.</span> <span class="toc-text">二、浅拷贝（Shallow Copy）</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E4%BB%80%E4%B9%88%E6%98%AF%E6%B5%85%E6%8B%B7%E8%B4%9D"><span class="toc-number">2.0.1.</span> <span class="toc-text">1.什么是浅拷贝?</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2%E3%80%81%E6%B5%85%E6%8B%B7%E8%B4%9D%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF"><span class="toc-number">2.0.2.</span> <span class="toc-text">2、浅拷贝使用场景</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#Object-assign"><span class="toc-number">2.0.2.0.1.</span> <span class="toc-text">Object.assign()</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%B1%95%E5%BC%80%E8%AF%AD%E6%B3%95-%C2%B7-%C2%B7-%C2%B7"><span class="toc-number">2.0.2.0.2.</span> <span class="toc-text">展开语法 · · ·</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E6%89%8B%E5%86%99%E5%AE%9E%E7%8E%B0%E6%B5%85%E6%8B%B7%E8%B4%9D"><span class="toc-number">2.0.2.0.3.</span> <span class="toc-text">手写实现浅拷贝</span></a></li></ol></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%B7%B1%E6%8B%B7%E8%B4%9D%EF%BC%88Deep-Copy%EF%BC%89"><span class="toc-number">3.</span> <span class="toc-text">三、深拷贝（Deep Copy）</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AF%E6%B7%B1%E6%8B%B7%E8%B4%9D%EF%BC%9F"><span class="toc-number">3.0.1.</span> <span class="toc-text">1、什么是深拷贝？</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2%E3%80%81%E6%B7%B1%E6%8B%B7%E8%B4%9D%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF"><span class="toc-number">3.0.2.</span> <span class="toc-text">2、深拷贝使用场景</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#JSON-parse-JSON-stringify-object"><span class="toc-number">3.0.2.0.1.</span> <span class="toc-text">JSON.parse(JSON.stringify(object))</span></a></li></ol></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%80%92%E5%BD%92"><span class="toc-number">3.0.3.</span> <span class="toc-text">递归</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%80%9A%E8%BF%87jQuery%E7%9A%84extend%E6%96%B9%E6%B3%95%E5%AE%9E%E7%8E%B0%E6%B7%B1%E6%8B%B7%E8%B4%9D"><span class="toc-number">3.0.4.</span> <span class="toc-text">通过jQuery的extend方法实现深拷贝</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#lodash%E5%87%BD%E6%95%B0%E5%BA%93%E5%AE%9E%E7%8E%B0%E6%B7%B1%E6%8B%B7%E8%B4%9D"><span class="toc-number">3.0.5.</span> <span class="toc-text">lodash函数库实现深拷贝</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E6%80%BB%E7%BB%93"><span class="toc-number">4.</span> <span class="toc-text">四、总结</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/89a6.html" title="总结(1.16)"><img src="https://api.ixiaowai.cn/gqapi/gqapi.php" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="总结(1.16)"/></a><div class="content"><a class="title" href="/posts/89a6.html" title="总结(1.16)">总结(1.16)</a><time datetime="2022-01-16T13:51:00.000Z" title="发表于 2022-01-16 21:51:00">2022-01-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/488c.html" title="JS函数柯里化"><img src="/../cover/currying.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS函数柯里化"/></a><div class="content"><a class="title" href="/posts/488c.html" title="JS函数柯里化">JS函数柯里化</a><time datetime="2021-12-07T06:37:00.000Z" title="发表于 2021-12-07 14:37:00">2021-12-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/2f90.html" title="总结(12.5)"><img src="https://tva4.sinaimg.cn/large/87c01ec7gy1frmmw9573mj21kw0w0npk.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="总结(12.5)"/></a><div class="content"><a class="title" href="/posts/2f90.html" title="总结(12.5)">总结(12.5)</a><time datetime="2021-12-05T03:17:00.000Z" title="发表于 2021-12-05 11:17:00">2021-12-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/dc34.html" title="Socket.IO使用"><img src="/../cover/socket.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Socket.IO使用"/></a><div class="content"><a class="title" href="/posts/dc34.html" title="Socket.IO使用">Socket.IO使用</a><time datetime="2021-11-30T01:19:00.000Z" title="发表于 2021-11-30 09:19:00">2021-11-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/b9e7e805.html" title="总结(11.27)"><img src="https://tva1.sinaimg.cn/large/0060lm7Tly1ftg6oqfp3aj318g0p0k4h.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="总结(11.27)"/></a><div class="content"><a class="title" href="/posts/b9e7e805.html" title="总结(11.27)">总结(11.27)</a><time datetime="2021-11-27T08:55:00.000Z" title="发表于 2021-11-27 16:55:00">2021-11-27</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="rightside.chat_btn"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'eHF7sUaBksaicGG9E3R7cdnJ-gzGzoHsz',
      appKey: 'nkwWdcso9uIl84CMuiYeg94T',
      placeholder: 'ヾﾉ≧∀≦)o来啊，快活啊!',
      avatar: 'monsterid',
      meta: 'nick,mail,QQ'.split(','),
      pageSize: '12',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: '',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: true,
      path: window.location.pathname,
      requiredFields: ["nick,mail"],
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/gh/HCLonely/Valine@latest/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><canvas id="universe"></canvas><script src="https://myhkw.cn/player/js/jquery.min.js" type="text/javascript"></script><script defer src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/star.js"></script><script async src="/js/diytitle.js"></script><script async data-pjax src="/js/randombg.js"></script><script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script><script async src="/js/weather.js"></script><script defer src="https://cdn.jsdelivr.net/npm/hexo-theme-volantis@latest/source/js/issues.min.js"></script><script src="/js/universe.js"></script><script src="https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js"></script><script> $(".category-list-count").prepend("<i class=\"fas fa-book\"></i>");</script><script> $(".category-list-item").eq(0).insertAfter($(".gallery-group-name").eq(0))</script><script> $(".category-list-item").eq(1).insertAfter($(".gallery-group-name").eq(1))</script><script> $(".category-list-item").eq(2).insertAfter($(".gallery-group-name").eq(2))</script><script> $(".category-list-item").eq(3).insertAfter($(".gallery-group-name").eq(3))</script><script> $(".category-list-item").eq(4).insertAfter($(".gallery-group-name").eq(4))</script><script> $(".category-list-item").eq(5).insertAfter($(".gallery-group-name").eq(5))</script><script> $(".category-list-item a").hide();</script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = false;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-show-text.min.js" data-mobile="false" data-text="富强,民主,文明,和谐,自由,平等,公正,法治,爱国,敬业,诚信,友善" data-fontsize="18px" data-random="true" async="async"></script><script src="//code.tidio.co/mxavk34b68alwnegypahsbiwew7digod.js" async="async"></script><script>function onTidioChatApiReady() {
  window.tidioChatApi.hide();
  window.tidioChatApi.on("close", function() {
    window.tidioChatApi.hide();
  });
}
if (window.tidioChatApi) {
  window.tidioChatApi.on("ready", onTidioChatApiReady);
} else {
  document.addEventListener("tidioChat-ready", onTidioChatApiReady);
}

var chatBtnFn = () => {
  document.getElementById("chat_btn").addEventListener("click", function(){
    window.tidioChatApi.show();
    window.tidioChatApi.open();
  });
}
chatBtnFn()
</script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = [
  'title',
  '#config-diff',
  '#body-wrap',
  '#rightside-config-hide',
  '#rightside-config-show',
  '.js-pjax'
]

if (false) {
  pjaxSelectors.unshift('meta[property="og:image"]', 'meta[property="og:title"]', 'meta[property="og:url"]')
}

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.removeEventListener('scroll', window.tocScrollFn)
  window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // Analytics
  if (false) {
    MtaH5.pgv()
  }

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start -->
  <script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/hexo-github-calendar@1.21/hexo_githubcalendar.js"></script>
  <script data-pjax>
        function GithubCalendarConfig(){
            var git_githubapiurl ="https://python-gitee-calendar-api.vercel.app/api?zhang_shaolong";
            var git_color =['#ebedf0', '#f1f8ff', '#dbedff', '#c8e1ff', '#79b8ff', '#2188ff', '#0366d6', '#005cc5', '#044289', '#032f62', '#05264c'];
            var git_user ="zhang_shaolong";
            var parent_div_git = document.getElementById('recent-posts');
            var git_div_html = '<div class="recent-post-item" style="width:100%;height:auto;padding:10px;"><div id="github_loading" style="width:10%;height:100%;margin:0 auto;display: block"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"  viewBox="0 0 50 50" style="enable-background:new 0 0 50 50" xml:space="preserve"><path fill="#d0d0d0" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z" transform="rotate(275.098 25 25)"><animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"></animateTransform></path></svg></div><div id="github_container"></div></div>';
            if(parent_div_git && location.pathname =='/'){
                console.log('已挂载github calendar')
                // parent_div_git.innerHTML=git_div_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",git_div_html) // 有报错，但不影响使用(支持pjax跳转)
            };
            GithubCalendar(git_githubapiurl,git_color,git_user)
        }
        if(document.getElementById('recent-posts')){
            GithubCalendarConfig()
        }
    </script>
    <style>#github_container{min-height:280px}@media screen and (max-width:650px) {#github_container{background-image:;min-height:0px}}</style>
    <style></style><script data-pjax>
  function butterfly_footer_beautify_injector_config(){
    var parent_div_git = document.getElementById('footer-wrap');
    var item_html = '<div id="workboard"></div><div id="ghbdages" style="overflow:hidden;max-height:90px;height:auto;text-align:center;margin-top:10px"><div class="swiper-wrapper"><div class="swiper-slide"><a class="github-badge" target="_blank" href="https://hexo.io/" style="margin-inline:5px" title="博客框架为Hexo_v5.4.0"><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&amp;logo=hexo" alt=""/></a><a class="github-badge" target="_blank" href="https://butterfly.js.org/" style="margin-inline:5px" title="主题版本Butterfly_v3.8.2"><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&amp;logo=bitdefender" alt=""/></a><a class="github-badge" target="_blank" href="https://www.jsdelivr.com/" style="margin-inline:5px" title="本站使用JsDelivr为静态资源提供CDN加速"><img src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&amp;logo=jsDelivr" alt=""/></a></div><div class="swiper-slide"><a class="github-badge" target="_blank" href="https://github.com/" style="margin-inline:5px" title="本站项目由Github托管"><img src="https://img.shields.io/badge/Source-Github-d021d6?style=flat&amp;logo=GitHub" alt=""/></a><a class="github-badge" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" style="margin-inline:5px" title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"><img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&amp;logo=Claris" alt=""/></a></div></div></div><style>a.github-badge:hover:before {display:none}</style>';
    console.log('已挂载butterfly_footer_beautify')
    parent_div_git.insertAdjacentHTML("beforeend",item_html)
    }
  var elist = '/about/'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_footer_beautify_injector_config();
  }
  else if (epage === cpage){
    butterfly_footer_beautify_injector_config();
  }
  </script><script async src="/js/runtime.js"></script><script defer src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js"></script><script defer data-pjax src="https://unpkg.zhimg.com/hexo-butterfly-footer-beautify/lib/swiperbdage_init.min.js"></script><script data-pjax>
  function butterfly_swiper_injector_config(){
    var parent_div_git = document.getElementById('recent-posts');
    var item_html = '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/dc34.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="../cover/socket.webp" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-11-30</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/dc34.html&quot;);" href="javascript:void(0);" alt="">Socket.IO使用</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/dc34.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/bf72.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="../img/垂直.png" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-10-24</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/bf72.html&quot;);" href="javascript:void(0);" alt="">一个盒子垂直水平居中有哪些方法？</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/bf72.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/a2b7.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="../img/assist/image2.png" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-11-02</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/a2b7.html&quot;);" href="javascript:void(0);" alt="">使用VuePress搭建vue组件库</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/a2b7.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/213d.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="../cover/business.jpg" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-05-12</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/213d.html&quot;);" href="javascript:void(0);" alt="">双飞翼布局和圣杯布局</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/213d.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/3079.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="https://api.ixiaowai.cn/gqapi/gqapi.php" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-04-03</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/3079.html&quot;);" href="javascript:void(0);" alt="">盒模型</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/3079.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
    console.log('已挂载butterfly_swiper')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'undefined'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_swiper_injector_config();
  }
  else if (epage === cpage){
    butterfly_swiper_injector_config();
  }
  </script><script defer src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js"></script><script defer data-pjax src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper_init.js"></script><!-- hexo injector body_end end --></body></html>